import java.util.ArrayDeque;

public class DeQue {
    public ArrayDeque<Integer> s1;
    public ArrayDeque<Integer> s2;


    public DeQue() {
        s1 = new ArrayDeque<>();
        s2 = new ArrayDeque<>();

    }

    public void push(int x) {
        s1.offer(x);

    }

    public int pop() {
        if (empty()) {
            return -1;
        }
        if (s2.isEmpty()) {
            while (!s1.isEmpty()) {
                s2.offer(s1.poll());
            }
            return s2.poll();

        } else {
            return s2.poll();


        }

    }

    public int peek() {
        if (empty()) {
            return -1;
        }
        if (s2.isEmpty()) {
            while (!s1.isEmpty()) {
                s2.offer(s1.poll());
            }
            return s2.peek();

        } else {
            return s2.peek();


        }


    }

    public boolean empty() {
        return s1.isEmpty() && s2.isEmpty();

    }
}
